import request, { type ListQuery, type ListResponse } from "@/utils/request";

const SUBJECT_BASE_URL = "/api";

const SubjectAPI = {
  getSubjectList: (params: SubjectListParams) => {
    return request.get<any, ListResponse<SubjectType>>(
      `${SUBJECT_BASE_URL}/internal/merchant/subject/`,
      {
        params,
      }
    );
  },
  addSubject: (data: Partial<SubjectType>) => {
    return request.post(`${SUBJECT_BASE_URL}/internal/merchant/subject/`, data, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },
  updateSubject: (data: Partial<SubjectType>) => {
    return request.put(`${SUBJECT_BASE_URL}/internal/merchant/subject/${data.id}/`, data, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },
  deleteSubject: (id: number) => {
    return request.delete(`${SUBJECT_BASE_URL}/internal/merchant/subject/${id}/`);
  },
};

export type SubjectListParams = {} & ListQuery;

export type SubjectType = {
  id: number;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  name: string;
  image_url: string;
  sequence: number;
};

export default SubjectAPI;
